package com.cskaoyan._19collection._04api;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author Macro_Ray
 * @since 2024/3/29 11:33
 */
/*
* void clearQ:清空collection
* boolean equals(object o) :判断是否相等
* int hashCode（):计算hashCode
* boolean isEmpty： 是否为空
* intsize():collection里面的元素个数*/
public class Demo2 {
    @Test
    public void test() {
        Collection<String> collection =new ArrayList<>();
        collection.add("hello");
        collection.add("world");
        collection.add("java");
        collection.add("python");

        System.out.println("collection.size() = " + collection.size());

        System.out.println("collection.isEmpty() = " + collection.isEmpty());


        collection.clear();
        System.out.println("collection.size() = " + collection.size());
        System.out.println("collection.isEmpty() = " + collection.isEmpty());
    }

    @Test
    public void test2() {
        Collection<String> collection1 =new ArrayList<>();
        collection1.add("hello");
        collection1.add("world");
        collection1.add("java");
        collection1.add("python");

        Collection<String> collection2 =new ArrayList<>();
        collection2.add("hello");
        collection2.add("world");
        collection2.add("java");
        collection2.add("python");

        System.out.println("collection1.equals(collection2) = " + collection1.equals(collection2));
    }

    @Test
    public void test3() {
        // int hashCode（):计算hashCode
        // Object里面的方法，如果不重写，默认调用Object的hashCode方法，返回对象的内存地址
        Collection<String> collection3 =new ArrayList<>();
        System.out.println("collection.hashCode() = " + collection3.hashCode());

        // String类重写了hashCode方法，返回字符串的hashcode值
        String str = "hello world";
        System.out.println("str.hashCode() = " + str.hashCode());

    }
}
